package com.zzc.study.config;

import com.zzc.study.listtener.TestChatModelListener;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.util.List;

@Configuration(proxyBeanMethods = false)
public class ChatLanguageModelConfig {

    /*@Bean
    public ChatLanguageModel chatLanguageModel()
    {
        return OpenAiChatModel.builder()
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .modelName("qwen-turbo-0624")
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .logRequests(true)// 日志界别设置为debug才有效
                .logResponses(true) // 日志界别设置为debug才有效
                .listeners(List.of(new TestChatModelListener())) //监听器
                .maxRetries(2)// 重试机制
                .timeout(Duration.ofSeconds(10)) // 设置10秒超时
                .build();
    }*/

    @Bean
    public ChatLanguageModel chatLanguageModel()
    {
        return OpenAiChatModel.builder()
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .modelName("qwen-turbo-0624")
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .logRequests(true)// 日志界别设置为debug才有效
                .logResponses(true) // 日志界别设置为debug才有效
                .listeners(List.of(new TestChatModelListener())) //监听器
                .maxRetries(3)// 重试机制
                .timeout(Duration.ofSeconds(10)) // 设置10秒超时
                .build();
    }
}
